package com.dao;

import com.pojo.Role;
import com.pojo.SysRole;
import com.vo.RoleVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author mornd
 * @date 2020/11/12 - 15:13
 */
public interface RoleDao {
    //根据用户id查询角色集合
    @Select("SELECT * FROM sys_role r INNER JOIN sys_user_role ur ON r.id = ur.rid AND ur.uid = #{userId}")
    List<SysRole> findRoleByUserId(Integer userId);

    //查询role
    List<Role> findRoleList(RoleVo roleVo);

    //添加role
    int addRole(Role role);

    //编辑role
    int updateRole(Role role);

    //删除role
    int deleteRole(Integer roleId);

    //检查该角色是否已有员工
    int checkRoleByUser(Integer roleId);

    //查询用户列表
    @Select("select * from sys_role")
    List<Map<String, Object>> findRoleListByMap();

    //根据用户id查询该用户所占角色id集合
    @Select("select rid from sys_user_role where uid = #{userId}")
    List<Integer> findRoleIdListByUserId(Integer userId);

    /**
     * 给角色添加菜单
     *
     * @param ids
     * @param roleId
     * @return
     */
    int addRolePermission(@Param("ids") List<Integer> ids, @Param("roleId") Integer roleId);

    /**
     * 给角色添加菜单之前先清空角色菜单表的关系
     *
     * @param roleId
     * @return
     */
    int clearRolePermission(Integer roleId);
}
